<%--
  Created by IntelliJ IDEA.
  User: Gao
  Date: 2023/3/21
  Time: 15:19
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <%@ include file="header.jsp"%>
</head>
<body>
    <%--/user?name=zhansgan&password=123--%>
    <form id="formId"  method="post">
        用户名：<input type="text" name="name"/><br/>
        密码：<input type="password" name="password"/><br/>
        验证码：<input type="text" name="code"/>
        <img id="verifyCodeId" src="<%=request.getContextPath()%>/verifyCode" onclick="refresh()"/>
        <br/>
        <input type="button" onclick="submitForm()" value="登录"/>
    </form>

    <script>
        function refresh() {
            $('#verifyCodeId').attr('src', '/verifyCode?' + Math.random());
        }

        function submitForm() {
            $.post(
                '/user?method=login',
                $('#formId').serialize(),
                function(jsonResult) {
                    //{'code':0,'msg':'删除成功'}
                    console.log(jsonResult);
                    if (jsonResult.ok) {
                        //mylayer.okMsg(jsonResult.msg)
                        mylayer.okUrl(jsonResult.msg, '/');
                    } else {
                        mylayer.errorMsg(jsonResult.msg);
                    }
                },
                'json'
            );
        }
    </script>
</body>
</html>
